import sqlite3

# Path to your .db file
db_file = "/home/shared/youtube-api-replication-package/output/mexico/2021-04-collection/202104_202203_02_mx_youtube_data.db" # Replace with your actual database file path

# Connect to the database
conn = sqlite3.connect(db_file)
cursor = conn.cursor()

# Query to list all tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")

# Fetch and print the table names
tables = cursor.fetchall()
print("Tables in the database:")
for table in tables:
    print(table[0])


# Iterate through the tables and count the number of records in each
for table in tables:
    table_name = table[0]
    cursor.execute(f"SELECT COUNT(*) FROM {table_name};")
    count = cursor.fetchone()[0]
    print(f"Total number of records in '{table_name}': {count}")

# Close the connection
conn.close()
